package com.lab303.powerproject.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.util.Random;

public class
 GenerateDemo {

    private static final Logger LOG = LoggerFactory.getLogger(GenerateDemo.class);

    public static float[] generateTemperature(float lowTem,float highTem){
        float[] temperatureArray = new float[24];
        temperatureArray[14] = highTem;
        temperatureArray[4] = lowTem;
        float difference = highTem-lowTem;
        for (int i = 0 ; i < 4 ; i++ ){
            float tem = (float) (lowTem+difference/(3+i)-(new Random().nextInt(6)*i*0.1));
            if (tem <= lowTem)
                i--;
            else {
                BigDecimal bigDecimal = new BigDecimal(tem);
                temperatureArray[i] = bigDecimal.setScale(1,BigDecimal.ROUND_HALF_UP).floatValue();
            }
        }
        for (int j = 5 ; j<14;j++){
            float tem = difference/13*(j-4);
            int flag = new Random().nextInt(2)==0?-1:1;
            float v = (float) (lowTem+tem+flag*new Random().nextInt(10)*0.1);
            BigDecimal bigDecimal = new BigDecimal(v);
            temperatureArray[j] = bigDecimal.setScale(1,BigDecimal.ROUND_HALF_UP).floatValue();
        }
        for (int k = 15 ; k<24;k++){
            float tem = difference/10*2/3*(k-14);
            int flag = new Random().nextInt(2)==0?-1:1;
            float v = (float) (highTem-tem+flag*new Random().nextInt(10)*0.1);
            BigDecimal bigDecimal = new BigDecimal(v);
            tem = bigDecimal.setScale(1,BigDecimal.ROUND_HALF_UP).floatValue();
            temperatureArray[k] = tem;
        }
        LOG.info("温度:");
        for(int i=0;i<temperatureArray.length;++i){
            LOG.info(" " + temperatureArray[i]);
        }
        LOG.info("\n");
        return temperatureArray;
    }

    public static float[] generateHumidity(float low,float high){
        float[] humidityArray = new float[24];
        humidityArray[4] = high;
        humidityArray[14] = low;
        float difference = high-low;
        for (int i = 0 ; i<4;i++){
            float v = high-difference/(8+i);
            BigDecimal bigDecimal = new BigDecimal(v);
            humidityArray[i] = bigDecimal.setScale(1,BigDecimal.ROUND_HALF_UP).floatValue();
        }
        for (int j = 5;j<14;j++){
            float tem = difference/9*(j-4);
            int flag = new Random().nextInt(2)==0?-1:1;
            float v = (float) (high-tem+flag*new Random().nextInt(10)*0.1);
            BigDecimal bigDecimal = new BigDecimal(v);
            humidityArray[j] = bigDecimal.setScale(1,BigDecimal.ROUND_HALF_UP).floatValue();
        }
        for (int k = 15;k<24;k++){
            float tem = (float) (difference/10*(k-14)*1.2);
            int flag = new Random().nextInt(2)==0?-1:1;
            float v = (float) (low+tem+flag*new Random().nextInt(10)*0.1);
            BigDecimal bigDecimal = new BigDecimal(v);
            tem = bigDecimal.setScale(1,BigDecimal.ROUND_HALF_UP).floatValue();
            humidityArray[k] = tem;
        }
        LOG.info("湿度:");
        for(int i=0;i<humidityArray.length;++i){
            LOG.info(" " + humidityArray[i]);
        }
        LOG.info("\n");
        return humidityArray;

    }

}
